﻿using System;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    class AddinUdf: ExternNameStructure
    {
        public AddinUdf(string name)
        {
            udfName = (ShortXLUnicodeString) name;
            _data = new byte[]{};
        }
        public override void Read(BinaryReader reader)
        {
            reader.ReadUInt32();
            udfName.Read(reader);
            ushort cb = reader.ReadUInt16();
            _data = reader.ReadBytes(cb);
        }

        public ShortXLUnicodeString udfName;
        public override string ToString()
        {
            return base.ToString() + (string)udfName;
        }
        private byte[] _data;

        public AddinUdf()
        {
        }

        public override void Write(BinaryWriter writer)
        {
            writer.Write((uint)0);
            udfName.Write(writer);
            writer.Write((ushort)_data.Length)
                ;
            writer.Write(_data);
        }

        public override string Name
        {
            get { return (string) this.udfName; }
        }
    }
}